package com.ict.web.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.ict.common.utils.bean.BeanUtils;
import com.ict.common.utils.uuid.IdUtils;
import com.ict.web.controller.file.domain.YzqFile;
import com.ict.web.controller.file.dto.YzqFileDTO;
import com.ict.web.domain.ExpertInformationSheet;
import com.ict.web.domain.ProfessionalQualification;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;

@Data
public class InsertProfessionalQualificationDto {

  @ApiModelProperty(value = "资格名称")
  private String qualificationName;

  @ApiModelProperty(value = "资格证号")
  private String QcNo;

  @ApiModelProperty(value = "注册单位")
  private String registeredUnit;

  @ApiModelProperty(value = "附件")
  private YzqFileDTO qualificationFile;

  @DateTimeFormat(pattern = "yyyy-MM-dd")
  @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8",shape = JsonFormat.Shape.STRING)
  @ApiModelProperty(value = "注册时间")
  private Date registrationTime;

  @DateTimeFormat(pattern = "yyyy-MM-dd")
  @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8",shape = JsonFormat.Shape.STRING)
  @ApiModelProperty(value = "过期时间")
  private Date expirationTime;



  public static ProfessionalQualification of(InsertProfessionalQualificationDto dto){
    ProfessionalQualification bean = new ProfessionalQualification();
    BeanUtils.copyProperties(dto,bean);
    //设置ID
    bean.setProfessionalId(IdUtils.snowId());
    //设置创建时间
    bean.setCreateTime(LocalDateTime.now());
    //设置创建时间
    bean.setUpdateTime(LocalDateTime.now());
    //设置物理删除标记
    bean.setDelFlag(ProfessionalQualification.DELETE_STATUS_NORMAL);
    return bean;
}

  /**
   * 将 InsertProfessionalQualificationDto中需传文件对象 转化为 file
   *
   * @param dto 接收dto
   * @return HotelInfo
   */
  public static ArrayList<YzqFile> toFile(ProfessionalQualification professionalQualification, InsertProfessionalQualificationDto dto) {
    ArrayList<YzqFile> fileList = new ArrayList<>();
    if (dto.getQualificationFile() != null) {
      YzqFileDTO Qf = dto.getQualificationFile();
      YzqFile fileQf = new YzqFile();
      fileQf.setId(String.valueOf(IdUtils.snowId()));
      BeanUtils.copyProperties(Qf, fileQf);
      fileList.add(fileQf);
      professionalQualification.setQualificationFile(fileQf.getId());
    }
    return fileList;
  }
}
